﻿// copyright jyz.2024


#include "AttributeMenuWidgetController.h"
#include "AbilitySystem/AuraAttributeSet.h"

void UAttributeMenuWidgetController::BroadcastInitialValues()
{
	UAuraAttributeSet* AS = CastChecked<UAuraAttributeSet>(AttributeSet);
	check(AttributeInfo);
	//FAuraAttributeInfoData Info = AttributeInfo->FindAttributeInfoForTag(FAuraGameplayTags::Get().AS_Primary_Strength);
	//Info.AttributeValue = AS->GetStrength();
	//AttributeInfoDelegate.Broadcast(Info);
	
	for(auto& Pair : AS->AttributeDelegateMap)
	{
		{
			BroadCastAttributeInfo(Pair.Key,Pair.Value().GetNumericValue(AttributeSet));
		}
		{
			AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(Pair.Value()).AddLambda([this,Pair](const FOnAttributeChangeData& Data)
			{
				BroadCastAttributeInfo(Pair.Key,Pair.Value().GetNumericValue(AttributeSet));
			});
		}
	}
}

void UAttributeMenuWidgetController::BroadCastAttributeInfo(const FGameplayTag& GameplayTag,float Value)const
{
	FAuraAttributeInfoData Info = AttributeInfo->FindAttributeInfoForTag(GameplayTag);
	Info.AttributeValue = Value;
	AttributeInfoDelegate.Broadcast(Info);
}
